<!--
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * @Date: 2022-04-07 20:18:30
 * @LastEditors: Sam
 * @LastEditTime: 2022-04-08 17:32:54
-->
<template>
    <div class="app-container">
        <el-card>
            <div slot="header" class="clearfix">
                <span>分销员订单</span>
            </div>
             <div class="filter-container">
                <el-input  v-model="listQuery.name" placeholder="请输入姓名" clearable style="width: 200px;margin-right: 10px;margin-bottom:10px" class="filter-item" @keyup.enter.native="handleFilter" />
                <el-input  v-model="listQuery.mobile" placeholder="请输入手机号" clearable style="width: 200px;margin-right: 10px;margin-bottom:10px" class="filter-item" @keyup.enter.native="handleFilter" />
                <el-select v-model="listQuery.status" placeholder="状态" clearable style="width: 200px;margin-right: 10px;" class="filter-item" @keyup.enter.native="handleFilter" >
                    <el-option  label="待入账" value="-1"></el-option>
                    <el-option  label="已入账" value="0"></el-option>
                    <el-option  label="已退款" value="-2"></el-option>
                </el-select>
      
                <el-button v-waves  class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
                {{ '搜索' }}
                </el-button> 
                <el-button v-waves class="filter-item" type="success" icon="el-icon-upload2" @click="handleExport">
                {{ '导出' }}
                </el-button>
            </div>
             <el-table
                v-loading="listLoading"
                :header-cell-style="{background:'#eef1f6',color:'#606266'}"
                :data="list"
                border
                fit
                highlight-current-row
                style="width: 100%"
                size="mini"
                >  
                 <!-- <el-table-column align="center" type="selection" width="55"> 
                </el-table-column> --> 
                <el-table-column  align="center" label="编号">
                <template slot-scope="scope">
                    <span>{{ scope.row.id }}</span>
                </template>
                </el-table-column>
            <el-table-column  align="center" label="分销员">
                <template slot-scope="scope">
                    <span>{{ scope.row.name }}</span>
                </template>
            </el-table-column>
            <el-table-column  align="center" label="手机号">
                <template slot-scope="scope">
                    <span>{{ scope.row.mobile }}</span>
                </template>
            </el-table-column>
            <el-table-column  align="center" label="订单">
                <template slot-scope="scope">
                    <span>{{ scope.row.order_sn }}</span>
                </template>
            </el-table-column>
            <el-table-column  align="center" label="订单金额">
                <template slot-scope="scope">
                    <span>{{ scope.row.order_pay_price }}</span>
                </template>
            </el-table-column>
            <el-table-column  align="center" label="状态">
                <template slot-scope="scope">
                    {{ scope.row.status_text }}
                </template>
            </el-table-column>
            <el-table-column  align="center" label="佣金">
                <template slot-scope="scope">
                    <span>{{ scope.row.user_commission }}</span>
                </template>
            </el-table-column>
                <!-- <el-table-column align="center" width="250" :label="'操作'">
                <template slot-scope="scope">
                    
                  
             
                </template>
                </el-table-column> -->
            </el-table>

            <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
        </el-card>
          <el-dialog :title="'详情'" :visible.sync="detail.dialogVisible" v-if="detail.dialogVisible">
            <detail :data="detail.data" />
         </el-dialog>
    </div>
</template>

<script>
    import {export_excell} from '@/api/export_excell' // 导出
    import waves from '@/directive/waves' // waves directive
    import permission from '@/directive/permission/index.js' // 权限判断指令
    import checkPermission from '@/utils/permission' // 权限判断函数
    import { list, detail } from '@/api/user_commission' // api接口
    import Detail from '@/components/Detail/detail' // 详情组件
    import { parseTime } from '@/utils' // 时间格式化函数
    import { getToken } from '@/utils/auth' // 获取token
    import Pagination from '@/components/Pagination' // 分页组件
    export default{
        name: 'user_commission_index',
        components: { Pagination,Detail }, // 引入组件
        filters: {
            parseTime // 时间过滤器
        },
        directives: { waves, permission }, // 引入指令
          data() {
            return {
             headerObj: {
                'Authorization': 'Bearer ' + getToken()
            },
            list: null, // 列表数据
            total: 0, // 总条数
            select_ids : [], // 选中的id集合
            levels:[],
            listLoading: true, //加载loadig
            listQuery: { //列表查询参数
                page: 1,
                limit: 10
            },

            detail: { // 详情
                dialogVisible: false,
                data: []
            }
            }
        },
          created() {
            this.getList()
        },
        methods: {
    
          

            handleExport(){
                export_excell(process.env.VUE_APP_BASE_API + 'admin/user_commission_export',this.listQuery);
            },
            checkPermission, // 权限判断函数
            handleFilter() { // 查询
                this.listQuery.page = 1
                this.getList()
            },
            
            handleDetail(index, row) { // 详情

                detail(row.id).then((res) => {
                        this.detail.dialogVisible = true
                        const data = res.data
                        this.detail.data = [
                                          {
                    name:"姓名",
                    content:data.name,
                    type: "text"
                },
                {
                    name:"手机号",
                    content:data.mobile,
                    type: "text"
                },
                {
                    name:"分销等级",
                    content:data.level,
                    type: "text"
                },
                {
                    name:"状态",
                    content:data.status_text,
                    type: "text"
                },
                {
                    name:"分销金额",
                    content:data.user_commission,  
                    type: "text"
                },

                        ]
                    })
                    },
            getList() { // 获取列表
                this.listLoading = true
                list(this.listQuery).then(response => {
                        this.list = response.data.data
                        this.total = response.data.total
                        this.listLoading = false
                    })
                },
            }
    }
</script>

